import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AddAndRemoveViewTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: '添加删除view',
      home: new SampleAppPage(),
    );
  }
}

class SampleAppPage extends StatefulWidget {
  SampleAppPage({Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _SampleAppPageState();
  }
}

class _SampleAppPageState extends State<StatefulWidget>{
  bool  toggle=true;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        title:new Text("SampleApp"),
      ),
      body: new Center(
        child:_getToggleChild(),
      ),
      floatingActionButton: new FloatingActionButton(onPressed: _toggle,tooltip: "Update Text",child: new Icon(Icons.update),),
    );
  }

  _getToggleChild(){
    if(toggle){
      return new Text("Toggle One");
    }else{
      return new MaterialButton(onPressed: (){},child:new Text('Toggle Two'));
    }
  }

  _toggle(){
    setState(() {
      toggle=!toggle;
    });
  }

}
